<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            选择物料
        </div>
    </header>
    <script id="mrlNameTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="setMrlName('{{= it[index].mrlGid }}','{{= it[index].mrlCode }}','{{= it[index].mrlName }}');">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-title">{{= it[index].mrlCode }}:{{= it[index].mrlName }}</div>
            </div>
        </li>
        {{~}}

    </script>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <div class="aui-searchbar" id="search" style="position: relative;">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <div class="aui-searchbar-input">
                    <form action="javascript:doSearch();">
                        <input type="search" placeholder="请输入物料编码" id="mrlCodeS">
                    </form>
                </div>
                <!-- <i class="aui-iconfont aui-icon-roundclosefill" tapmode onclick="clearInput()"></i> -->
            </div>
            <div class="aui-btn aui-btn-primary" style="margin-right: 0.5rem;background-color: #03a9f4" onclick="doSearch()">搜索</div>
            </div>
             
            <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">
                <table class="table" style='width:100%;' id="table">
                    <thead>
                        <tr
                            style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                            
                        <td>序号</td>
                            <td algin='center'>物料号</td>
                            <td algin='center'>物料名</td>
                            <td algin='center'>数量</td>
                            <td algin='center'>批次</td>
                            <td></td>
                        </tr>
                    </thead>
                    <tbody id="tbodyHtml">
                    </tbody>
                </table>
            </div>
        
        <ul class="aui-list aui-list-in" id="mrlNameList">

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<!-- <script src="../script/zepto.min.js"></script> -->
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    apiready = function() {

        getMrlNameList();

    };

    //查询仓库列表
    function getMrlNameList() {

        //取仓库GID  
        var workCenterGid = api.pageParam.workCenterGid;
        //取库位GID
        var workCellGid = api.pageParam.workCellGid;

        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMrlNameList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                workCenterGid: workCenterGid, //仓库GID  
                workCellGid: workCellGid, //库位GID
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
                        
                        html += "<td name='seqno' style='width:40px;'>" + (i + 1) + "</td>";
                        
                        
                        html += "<td name='mrlCode'>" + list[i].mrlCode + "</td>";
                        html += "<td name='mrlName'>" + list[i].mrlName + "</td>";
                        
                        html += "<td name='qty'>" + list[i].qty + "</td>";
                        html += "<td name='lotCode'>" + list[i].lotCode + "</td>";
                        
                        html +="<td><button name='sub' type='checkbox' onclick='setMrlName(\""+list[i].mrlGid+"\",\""+list[i].mrlCode+"\",\""+list[i].mrlName+"\")' /></td>";
                        html += "</tr>";
                        
                        
                    }
                    $api.html($api.byId("tbodyHtml"), html);
                   /*  var mydata = myobj.list;
                    var evaluation = doT.template($api.dom('#mrlNameTemp').innerHTML);
                    $api.dom('#mrlNameList').innerHTML = evaluation(mydata); */
                } else {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选则返回函数
    function setMrlName(mrlGid, mrlCode, mrlName) {
        api.closeWin();
        
        var name = api.pageParam.name;

            api.execScript({
                name: name,
                script: 'setMrlName("' + mrlGid + '","' + mrlCode + '","' + mrlName + '")'
            });

    }

    //库位编码查询
    function doSearch() {
        var workCenterGid = api.pageParam.workCenterGid;
        //取库位编码  --库内转移业务用
        //取库位GID
        var workCellGid = api.pageParam.workCellGid;
        var kwcode = api.pageParam.kwcode;
        var mrlCodeS = $("#mrlCodeS").val();
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMrlNameList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                workCellGid: workCellGid, 
                workCenterGid: workCenterGid, 
                mrlCodeS: mrlCodeS,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    /* var mydata = myobj.list;
                    var evaluation = doT.template($api.dom('#mrlNameTemp').innerHTML);
                    $api.dom('#mrlNameList').innerHTML = evaluation(mydata); */
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
                        
                        html += "<td name='seqno' style='width:40px;'>" + (i + 1) + "</td>";
                       
                        
                        
                        html += "<td name='mrlCode'>" + list[i].mrlCode + "</td>";
                        html += "<td name='mrlName'>" + list[i].mrlName + "</td>";
                        
                        html += "<td name='qty'>" + list[i].qty + "</td>";
                        html += "<td name='lotCode'>" + list[i].lotCode + "</td>";
                        html +="<td><button name='sub' type='checkbox' onclick='setMrlName(\""+list[i].mrlGid+"\",\""+list[i].mrlCode+"\",\""+list[i].mrlName+"\")' /></td>";
                        html += "</tr>";
                        
                    }
                    $api.html($api.byId("tbodyHtml"), html);
                } else {
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
